package StudyCode.summary.mycollection;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class CreateMapFromKeysAndValuesLists {
	public static <K, V> Map<K, V> createMap(final List<K> keys,
	                                         final List<V> values)

			throws IllegalArgumentException {

		return createMap((K[]) keys.toArray(), (V[]) values.toArray());
	}


	public static <K, V> Map<K, V> createMap(final K[] keys,
	                                         final V[] values) throws IllegalArgumentException {

		final Map<K, V> map = new HashMap<>(keys.length);

		for (int i = 0; i < keys.length; i++) {
			map.put(keys[i], values[i]);
		}

		return map;
	}


	public static <I, K, V> Map<K, V> createMap(final Map<I, K> keys,
	                                            final Map<I, V> values) {


		final Map<K, V> map = new HashMap<>(keys.size());

		for (final I entryKey : keys.keySet()) {
			map.put(keys.get(entryKey), values.get(entryKey));
		}

		return map;
	}
}
